<template>
    <div>
        <van-nav-bar
            title="添加地址"
            left-text="返回" 
            left-arrow
            @click-left="onClickLeft"/>
         <!-- 新增地址 -->
        <van-address-edit
            :area-list="areaList"
            show-postal
            show-delete
            show-set-default
            show-search-result
            :search-result="searchResult"
            :area-columns-placeholder="['请选择', '请选择', '请选择']"
            @save="onSave"
            @delete="onDelete"
            @change-detail="onChangeDetail"/>

    </div>
</template>

<script>
import { areaList } from '@vant/area-data';
 import { Toast } from 'vant';
 import { addaddressApi } from '../../apis/harvestAddress'
    export default {
    data() {
        return {
        areaList,
        searchResult: [], 
        userInfo:{
            userId: '',
            phone: '',
            name: '',
            address: '',
            tag: '1'  
            }, 
        };
    },
    mounted(){ 
        console.log(this.searchResult);
    },
    methods: {
        // 点击返回
        onClickLeft(){
            this.$router.go(-1)
        },

        onSave(content) {
        Toast('已添加成功');
            this.userInfo.userId =content.tel
            this.userInfo.phone = content.tel
            this.userInfo.name = content.name
            this.userInfo.address = content.province + '/' + content.city + '/' + content.county + '/' + content.addressDetail
            /* console.log(this.userInfo);  */ 
            
            let shuju = addaddressApi(this.userInfo,)
          console.log(shuju);
        },

        onDelete() {
            Toast('delete');
        },

        onChangeDetail(val) {
        if (val) {
            this.searchResult = [
            {
                name: '黄龙万科中心',
                address: '杭州市西湖区',
            },
            ];
        } else {
            this.searchResult = [];
        }
        },
    },
    };


</script>
 